﻿$(document).ready(function(e) {
	///////////////////////弹出登录框
				
				
				var name_text="";
				var password_text;
				var win_height = $(document).height();               //浏览器时下窗口文档的高度
				var win_width = $(document).width();               //浏览器时下窗口文档的宽度
				
				var tanchuceng_width = $("#tanchuceng").width();     ////////获得弹出层的宽度
				var tanchuceng_height = $("#tanchuceng").height();     ////////获得弹出层的高度
				var margin_left_to_righ = win_width - tanchuceng_width;      /////弹出层左边距离浏览器文档右边的距离
				var margin_top_to_bottom = win_height - tanchuceng_height;     /////弹出层顶部距离浏览器文档底部的距离
				var window_width = $(window).width();          //浏览器时下窗口可视区域宽度
				var window_height = $(window).height();          //浏览器时下窗口可视区域高度
				var tanchuceng_left = (window_width-tanchuceng_width)/2;
				var tanchuceng_top =  parseInt($("#tanchuceng").css("margin-top"));
				var yidong_width,yidong_height ;     ////每次鼠标移动的宽度和高度
				var old_pageX,old_pageY,new_pageX,new_pageY;
				var key_num_left;
				
				$("#login_logo").mousedown(function(e){
					
					old_pageX = e.pageX;
					old_pageY = e.pageY;
					key_num_left = e.which;
					//$("#show_daan").html(tanchuceng_top);
					if(key_num_left==1){
					//yidong_width = f.pageX - old_pageX;
					//old_pageX = f.pageX ;
						$(document).mousemove(function(f){
						yidong_width = f.pageX - old_pageX;
						yidong_height = f.pageY - old_pageY;
						old_pageX = f.pageX;
						old_pageY = f.pageY;
						tanchuceng_left = tanchuceng_left + yidong_width;
						tanchuceng_top = tanchuceng_top + yidong_height;
						if(tanchuceng_left<=0){
							tanchuceng_left=0;
						}
						else if(tanchuceng_left>=margin_left_to_righ){
							tanchuceng_left = margin_left_to_righ;
						}
						if(tanchuceng_top<=0){
							tanchuceng_top=0;
						}
						else if(tanchuceng_top>=margin_top_to_bottom){
							tanchuceng_top = margin_top_to_bottom;
						}
						$("#tanchuceng").css("margin-left",tanchuceng_left);
						$("#tanchuceng").css("margin-top",tanchuceng_top);
					//	$("#show_daan").html(yidong_width);
						});             /////////$(document).mousemove    结束
					
					}         /////////if(key_num_left==1) 结束
					});
				$(document).mouseup(function(){
						$(document).unbind("mousemove");
					});
				
				$(window).resize(function () {          //当浏览器大小变化时
   					window_width = $(window).width();          //浏览器时下窗口可视区域高度
					tanchuceng_left = (window_width-tanchuceng_width)/2;
					$("#tanchuceng").css("margin-left",tanchuceng_left);
				});
				$("#login").click(function(){
					$("#fugaiceng").css("display","block");
					$("#fugaiceng").css("height",win_height);
					$("#tanchuceng").css("display","block");
					$("#tanchuceng").css("margin-left",tanchuceng_left);
					$("#show_daan").html(win_height);
					});
				$("#login_close").click(function(){
					
					$("#fugaiceng").css("display","none");
					$("#tanchuceng").css("display","none");
					});
				
				
				$("#input_place1").focusout(function(e) {
                    $("#input_place1").css("border","1px solid #E6E6E6");
                });
				$("#input_place1").focus(function(){
						//$("#input_place1").css("border","1px solid blue");
						$("#input_place1").keyup(function(e){
							name_text = $("#input_place1").val();

							if(name_text==""){				
							$("#input_place1").css("background-image","url(../images/login_2.png)");
							$("#input_place1").css("background-repeat","no-repeat");
							}
							if(name_text!=""){
							$("#input_place1").css("background-image","none");
							}
						});
						
					});		
				
				$("#input_place2").focusout(function(e) {
                    //$("#input_place2").css("border","1px solid #E6E6E6");
                });			
				$("#input_place2").focus(function(){
					//$("#input_place2").css("border","1px solid blue");					
					$("#input_place2").keyup(function(){
							
							password_text = $("#input_place2").val();

							if(password_text==""){				
							$("#input_place2").css("background-image","url(../images/login_3.png)");
							$("#input_place2").css("background-repeat","no-repeat");
							}
							if(password_text!=""){
							$("#input_place2").css("background-image","none");
							}
						});
					});
					
					
			//IE
            if(!$.support.leadingWhitespace){
                  $("#input_place1").get(0).attachEvent("onpropertychange",function (o){

						 var text = o.srcElement.value;
						 if(text!=""){
							 $("#input_place1").css("background-image","none");
						 }
						 //$("#login_tishi").html(text);
                    });
				$("#input_place2").get(0).attachEvent("onpropertychange",function (o){

						 var text = o.srcElement.value;
						 if(text!=""){
							 $("#input_place2").css("background-image","none");
						 }
						// $("#login_tishi").html(text);

                    });
            //非IE
            }else{
            $("#input_place1").get(0).addEventListener("input",function(o){
					var text = o.srcElement.value;
						 if(text!=""){
							 $("#input_place1").css("background-image","none");
						 }
						 //$("#login_tishi").html(text);
                },false);
				
			$("#input_place2").get(0).addEventListener("input",function(o){
					var text = o.srcElement.value;
						 if(text!=""){
							 $("#input_place2").css("background-image","none");
						 }
                },false);
            }
			$("#input_submit").mouseenter(function(){
				$("#input_submit").css("background-color","#4242FF");
				});
			$("#input_submit").mouseleave(function(){
				$("#input_submit").css("background-color","#3F89EC");
				});
				///////////////////////弹出登录框  end
				
			////////////验证码开始
			$("#checkImg2").click(function(){
				$("#checkImg2").attr("src","ValidationCode.class.php?num="+Math.random());
			});
			
			$("#login_input_checkcode").blur(function(){
				$.post("checkCode.php",{validateCode:$("#login_input_checkcode").val()},function(data){
					if(data=="1"){
						$("#login_tishi").html("");
					}
					else if(data=="0"){
						$("#login_tishi").html("验证码错误！");
					}
				});
			});
			
			$("#input_place1").blur(function(){
				var username = $("#input_place1").val();
				if(username==""){
					$("#login_tishi").html("请您填写用户名。");
				}
				else{
					$.post("checkname.php",{user_name:username},function(data){
     				// alert("数据：" + data);
	  				if(data=="1"){                       ///////账号不存在，可以注册
						$("#login_tishi").html("");
					}
					else if(data=="2"){                   //////账号已存在并且已激活
						$("#login_tishi").html("账号未激活。");
					}
					else if(data=="3"){                   ////激活码未过期
						$("#login_tishi").html("账号不存在。");
					}
    			});           ////post   结束
					
					
					//$("#login_tishi").html("");
				}
			});
			
			$("#input_place2").blur(function(){
				var username = $("#input_place2").val();
				if(username==""){
					$("#login_tishi").html("请您输入密码。");
				}
				else{
					$("#login_tishi").html("");
				}
			});
			////////////验证码结束
});
function login_yanzheng(form){
	var username = $("#input_place1").val();
	var password = $("#input_place2").val();
	var checkcode = $("#login_input_checkcode").val();
	var p_tishi = $("#login_tishi").text();
	if(username==""){
		$("#login_tishi").html("请您填写用户名。");
		return false;
	}
	else if(password==""){
		$("#login_tishi").html("请您输入密码。");
		return false;
	}
	else if(checkcode==""){
		$("#login_tishi").html("请输入验证码。");
		return false;
	}
	else if(p_tishi!=""){
		return false;
	}
	return true;
}